<template>
	<view class="flex-col page">
		<view class="flex-col group">
			<view class="flex-col group_1">
				<image src="../../static/imgs/meituandz.png" class="image_1 my-4" />
				<view class="justify-between section_2 mt-4 ps-12">
					<!-- <text>输入美团/点评验劵</text> -->
					<input placeholder="输入美团/点评验券" v-model="group_code" type="text"
						placeholder-style="font-size: 32rpx;font-weight: 500;color: #AAB5BF;" class="ipt" />
					<view class="d-flex align-items-center " @click="getCode">
						<image src="../../static/imgs/scan.png" class="image_2 me-12 flex-1 ms-12" />
					</view>
				</view>
			</view>
			<view class="position-fixd save-action ">
				<view class="px-3">
					<button class="button font-20 bg-theme" :disabled="!group_code" @click="submit">提交</button>
				</view>
			</view>


		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				group_code: '',
			};
		},
		onLoad() {
			uni.hideShareMenu()
		},
		methods: {

			getCode() {
				wx.scanCode({
					success: (res) => {
						this.group_code = res.result
					}
				})
			},

			submit() {
				if (0 == this.group_code.length) {
					this.$u.toast('请输入团券');
					return
				}
				uni.showModal({
					title: '提示',
					content: `请确认使用 ${this.group_code} 团券进行兑换吗？`,
					success: (res) => {
						if (res.confirm) {
							this.$u.api.exchangeDZMT({
								code: this.group_code,
							}).then(res => {
								console.log(res)
								if (1 == res.code) {
									uni.showModal({
										title: '提示',
										content: `团购券 ${res.data.group_title} 兑换成功，请到我的卡券进行查看`,
										showCancel: false,
										success: () => {
											this.group_code = ''
											this.getInfo()
											this.$u.route({
												url: 'pages/myCenter/myVoucher',
											})
										}
									})
								} else {
									uni.showModal({
										title: '提示',
										content: res.msg,
										showCancel: false,
										complete: () => {
											this.group_code = ''
										}
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},

			getInfo() {
				if (this.vuex_has_login) {
					this.$u.api.getUserInfo().then(res => {
						this.$u.vuex('vuex_user', {
							...this.vuex_user,
							...res.data
						})
					})
				}
			},
		}
	};
</script>

<style scoped lang="scss">
	.page {
		background-color: #ffffff;
		width: 100%;
		overflow-y: auto;
		height: 100%;

		.section_1 {
			padding: 16rpx 24rpx;
			color: rgb(51, 51, 51);
			font-size: 28rpx;
			font-weight: 600;
			line-height: 40rpx;
			white-space: nowrap;
			background-color: rgb(243, 243, 243);

			.text {
				margin: 6rpx 0;
			}

			.image {
				border-radius: 26rpx;
				width: 156rpx;
				height: 52rpx;
			}
		}

		.group {
			margin-top: 64rpx;
			padding: 0 32rpx;

			.group_1 {
				color: rgb(105, 105, 105);
				font-size: 28rpx;
				font-weight: 600;
				line-height: 40rpx;
				white-space: nowrap;

				.image_1 {
					align-self: center;
					width: 200rpx;
					height: 104rpx;
				}

				.section_2 {
					margin-top: 30rpx;
					// padding: 0rpx 18rpx;
					border-radius: 8rpx;
					display: flex;
					align-items: center;
					background: #F5F7F8;

					.ipt {
						flex: 1;
						padding: 15rpx 12rpx;
						background: #F5F7F8;
						font-size: 36rpx;
						font-weight: 500;
						padding: 30rpx 0;
						color: #222426;
					}

					.image_2 {
						width: 48rpx;
						height: 48rpx;
					}
				}
			}

			.save-action {
				left: 50%;
				transform: translateX(-50%);
				bottom: 128rpx;
				width: 100%;

				.button {
					padding: 0 16px;
					height: 96rpx;
					line-height: 96rpx;
					color: rgb(255, 255, 255);
					font-weight: 600;
					border-radius: 40rpx 0 40rpx 40rpx;

					&[disabled]:not([type]) {
						background-color: #AAB5BF !important;
					}
				}
			}
		}
	}
</style>